package com.zhimu.boot.activemq.produce;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.Queue;
import java.util.UUID;

/**
 * @Author: Alvin
 * @Date: 2019/6/23 16:05
 * @Description
 */
@Component
public class Queue_Produce {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
    @Resource
    private Queue queue;

    public void produceMessage() {
        jmsMessagingTemplate.convertAndSend(queue, "***********" + UUID.randomUUID().toString().substring(0, 6));
    }

    @Scheduled( fixedDelay = 3000L)
    public void produceMessageScheduled(){
        jmsMessagingTemplate.convertAndSend(queue, "***********Scheduled:" + UUID.randomUUID().toString().substring(0, 6));
        System.out.println("Scheduled send msg ok");
    }

}

